package com.ninthgroup.controller;

import com.ninthgroup.entity.Permission;
import com.ninthgroup.service.PermissionService;
import com.ninthgroup.vo.PermissionVo;
import com.ninthgroup.vo.Result;
import com.ninthgroup.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author ：1452863884@qq.com rcg
 * @date ：Created in 2022/10/14 11:28
 * @description：权限的控制层
 * @modified By：
 * @version:1.0
 */
@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;


    @GetMapping("/leftPermission")
    public Result leftPermission(){

        return permissionService.findByAId();
    }

    @GetMapping("/list")
    public Result list(Integer roleId){
        System.out.println("roleId = " + roleId);
        return permissionService.findByRoleId(roleId);
    }

    @PostMapping("qr")
    public Result qr(Integer roleId,Integer[] permissionIds){
        return permissionService.qr(roleId,permissionIds);
    }


    @PostMapping("/all")
    public Result all(
            @RequestParam(defaultValue = "1") Integer currentPage,
            @RequestParam(defaultValue = "5") Integer pageSize,
            @RequestBody PermissionVo permissionVo
            ){
        System.out.println("permissionVo = " + permissionVo);
        return permissionService.selectAll(currentPage,pageSize,permissionVo);
    }


    @PostMapping("/add")
    public Result add(@RequestBody Permission permission){

       return permissionService.insertPermission(permission);
    }

    @PostMapping("/update")
    public Result update(@RequestBody Permission permission){

       return permissionService.updatePermission(permission);
    }
    @GetMapping("/del")
    public Result delete(Integer pId){

       return permissionService.deletePermission(pId);
    }


}